package com.itheima.brand.controller;

import com.itheima.brand.service.BrandService;
import com.itheima.goods.pojo.Brand;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    //查询所有品牌
    @GetMapping("")
    public Result findAll() {


        return brandService.findAll();
    }

    //增加品牌
    @PostMapping("")
// 	获取请求携带的json格式字符串,并解析json格式的字符串，将数据封装到对应的vo对象                  中或直接存放到字符串中
    public Result add(@RequestBody Brand brand) {

        return brandService.add(brand);
    }
    //分类查询品牌
    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page,@PathVariable("size") Integer size) {

        return brandService.findPage(page,size);
    }
    //分类查询品牌
    @PostMapping("/search/{page}/{size}")
    public Result findPage2(@PathVariable("page") Integer page,
                            @PathVariable("size") Integer size,
                            @RequestBody Brand brand ) {

        return brandService.findPage2(page,size,brand);
    }
    //根据id查询品牌
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id) {

        return brandService.findById(id);
    }
    //更新品牌
    @PutMapping("/{id}")
    public Result updateBrand(@RequestBody Brand brand,@PathVariable("id") Integer id) {

        return brandService.updateBrand(brand,id);
    }
    //删除品牌
    @DeleteMapping ("/{id}")
    public Result deleteBrand(@PathVariable("id") Integer id) {

        return brandService.deleteBrand(id);
    }
}
